﻿using Enterprise_Get.API.Infrastructures.Interfaces;
using MediatR;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.BasicInformation.Departments;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Get.API.Application.Commands.BasicInformations
{
    public class EnterpriseShowHandler : IRequestHandler<EnterpriseShowCommand, THE_WIND_RISES.Common.Dtos.Result>
    {
        /// <summary>
        /// 企业仓储
        /// </summary>
        private readonly IBaseRepositoryGet<Enterprise> enterpriseRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="enterpriseRepository"></param>
        public EnterpriseShowHandler(IBaseRepositoryGet<Enterprise> enterpriseRepository)
        {
            this.enterpriseRepository = enterpriseRepository;
        }

        /// <summary>
        /// 业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(EnterpriseShowCommand request, CancellationToken cancellationToken)
        {
            var result = new THE_WIND_RISES.Common.Dtos.Result() { Code = (int)CommonErrorCodes.Search };

            try
            {
                string sql = "select * from Enterprise";
                var list = enterpriseRepository.GetAll(sql);
                if (list != null)
                {
                    result.Code = (int)CommonErrorCodes.Success;
                    result.Data = list;
                    result.Msg = "显示成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
